//
//  EnterPasswordViewController.swift
//  todoApp
//
//  Created by gu on 15/5/20.
//  Copyright (c) 2015年 ll studio. All rights reserved.
//

import UIKit

class EnterPasswordViewController: UIViewController {

    var phone:String!
    @IBOutlet var password: UITextField!
    @IBOutlet var repassword: UITextField!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    
    
    
    @IBAction func tijiao(sender: UIButton) {
        if password.text?.characters.count < 6 {
            UIAlertView.showWithTitle("", message: ("密码必须不小于6位"), cancelButtonTitle: "确定", otherButtonTitles: [], tapBlock: nil)
            return
        }else if password.text != repassword.text
        {
            UIAlertView.showWithTitle("", message: ("两次输入密码不一致"), cancelButtonTitle: "确定", otherButtonTitles: [], tapBlock: nil)
            return;
        }
        
        
        var accountObj = AVObject(className: "AccountClass")
        accountObj.setObject(phone, forKey: "userAccount")
        accountObj.setObject(password.text, forKey: "userPassword")
        accountObj.setObject(phone, forKey: "acountName")
        accountObj.setObject(false, forKey: "isThirdPartLogin")
        
        self.showIndicatorWithContent("正在注册")
        
        var ret = accountObj.save() as Bool
        
        self.hideIndicator()
        
        if(ret == true) {
            //存储数据
            
            NSUserDefaults.standardUserDefaults().setObject(phone, forKey:"userAccount")
            NSUserDefaults.standardUserDefaults().setObject(phone, forKey:"acountName")
            NSUserDefaults.standardUserDefaults().synchronize()
            NSUserDefaults.standardUserDefaults().setBool(true, forKey:"isUserLoggedIn")
            //显示注册成功信息
            
            //self.presentViewController(myAlert, animated: true, completion: nil)
            
            UIAlertView.showWithTitle("注册成功", message: "", cancelButtonTitle: "ok", otherButtonTitles: nil, tapBlock: nil)
            self.dismissViewControllerAnimated(true, completion: nil)
//            if (delegate != nil) {
//                delegate.verifyCompleted()
//            }
            //self.back()
        }

    }

    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    
}
